package org.springblade.modules.repair.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.modules.repair.entity.MaintainParts;
import org.springblade.modules.repair.service.MaintainPartsService;
import org.springblade.modules.repair.vo.MaintainPartsTreeVO;
import org.springblade.modules.repair.vo.MaintainPartsVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("repair/parts")
@Api(value = "配件分类表", tags = "配件分类接口")
public class MaintainPartsController {

	private final MaintainPartsService maintainPartsService;

	@GetMapping("/list")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "列表")
	public R<List<MaintainPartsVO>> list(MaintainParts maintainParts) {
		List<MaintainPartsVO> list = maintainPartsService.partsList(maintainParts);
		return R.data(list);
	}

	@GetMapping("/tree")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "树形列表")
	public R<List<MaintainPartsTreeVO>> tree(MaintainParts maintainParts) {
		List<MaintainPartsTreeVO> list = maintainPartsService.partsTree(maintainParts);
		return R.data(ForestNodeMerger.merge(list));
	}

	@GetMapping("/getElevatorStructureTree")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "获取电梯结构模板关联配件树")
	public R<List<MaintainPartsTreeVO>> getElevatorStructureTree(@ApiParam(value = "电梯id") @RequestParam Long elevatorId) {
		List<MaintainPartsTreeVO> list = maintainPartsService.getElevatorStructureTree(elevatorId);
		return R.data(ForestNodeMerger.merge(list));
	}

}
